<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>专项计划新增</title>
    <script src="/scripts/boot.js"></script>
</head>
<body class="bg-white">
<div id="viewForm">
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>选择主项计划
            </td>
            <td>
                <input type="hidden" class="mini-hidden" name="id"/>
                <select id="planId" name="planId" class="mini-combobox w250" ajaxType="post" url="/mainPlan/list" textField="name" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
            </td>
            <td class="text-titlebg">
                <span class="color-red">*</span>业务类型
            </td>
            <td>
                <input type="hidden" class="mini-hidden" name="id"/>
                <select id="professionType" name="professionType" class="mini-combobox w250" ajaxType="post" url="/businessType/listAll" textField="typeName" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择" onvaluechanged="listTempleteByPerfessionType"></select>
            </td>
        </tr>
        <tr>
      		<td class="text-titlebg noEmpty"><span class="color-red">*</span>计划名称</td>
            <td>
                <div id="name" name="name" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"></div>
            </td>
            <td class="text-titlebg">
                <span class="color-red">*</span>模板
            </td>
            <td>
                <input type="hidden" class="mini-hidden" name="id"/>
                <select id="planTempleteId" name="planTempleteId" class="mini-combobox w250"  ajaxType="post"  textField="name" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
            </td>
        </tr>
    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">下一步</a>
    </div>
</div>
<script type="text/javascript">
	var post_flag,form;
	
	function listTempleteByPerfessionType(){ 
		var professionTypeId = mini.get("professionType").getSelected().id;
		mini.get("planTempleteId").load("/planTemplete/listTempleteByPerfessionType?perfessionTypeId="+professionTypeId)
	}
	
    var view = {
        init: function () {
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
        },
        //保存
        save: function () {
            form.validate();
            if (form.isValid() == false) return;
            if (post_flag) return;
            var data = form.getData();//获取表单多个控件的数据
            data['plan.id']=data.planId;
            data['planTemplete.id']=data.planTempleteId
            delete data["planId"];
            delete data["planTempleteId"]
            post_flag = true;
            $.ajax({
                url: "/professionalPlan/save",
                type: "post",
                data: data,
                success: function (msg) {
                    post_flag = false;
                    if(typeof(msg) == "string") {
                		msg = $.parseJSON(msg);
                	}
                	if(msg.state){
	                    mini.open({
	                        url: "/planning/specialPlan/plannList.html",
	                        title: "项目专项节点计划编制", width: $(window.parent.document).width()-280, height: 700,
	                        onload: function () {
	                            var data = {"id": msg.body[0].planId,'name':mini.get("name").getValue()};
	                            var iframe = this.getIFrameEl();
	                            iframe.contentWindow.view.SetData(data);
	
	                        },
	                        ondestroy: function (action) {
	                            CloseWindow('ok');
	                        }
	                    });
                	}else{
                		mini.alert(msg.message);
                	}
                },
                error: function (errorMsg) {
                    post_flag = false;
                }
            });
        },
//    数据展示
        SetData: function (data) {
            data = mini.clone(data);
            state = data.state;
            if(data.state=="edit"){
                $.ajax({
                    url:"/messageRemind/info?id=" + data.id,
                    type: "post",
                    success: function (text) {
                        //跨页面传递的数据对象，克隆后才可以安全使用
                        datas = mini.decode(text);   //反序列化成对象
                        form.setData(datas);             //设置多个控件数据
                    }
                });
            }else{
                $('input[name=id]').val("");
            }
        }
    };
    view.init();
</script>
</body>
</html>